//
//  ViewController.m
//  18-SQLite
//
//  Created by dllo on 16/8/8.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"
@interface ViewController ()

@property (nonatomic, strong)SQLiteDataBaseManager *dataBaseManager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataBaseManager = [SQLiteDataBaseManager sharedManager];
    // SQLite3
    // 注意使用SQLite3.0.tdb
    // 注意使用SQLite3.0.tdb 和 注意使用SQLite3.tdb 区别
    // 3.0 是 3的替身文件, 防止用户误删
}
- (IBAction)openSQLite:(id)sender {
    [_dataBaseManager openSQLite3];
}
- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManager closeSQLite3];
}
- (IBAction)creatTable:(id)sender {
    [_dataBaseManager creatTable];
}
- (IBAction)addTable:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 12;
    stu.stu_name = @"0.0";
    [_dataBaseManager insertStu:stu];
}
- (IBAction)removeTable:(id)sender {
    // 删除表
    // SQL语句: drop table 表名
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 12;
//    stu.stu_name = @"0.0";
//    [_dataBaseManager deleteStu:stu];
    [_dataBaseManager deleteAll];
}

- (IBAction)updateName:(id)sender {
    [_dataBaseManager updateOldName:@"xx" newName:@"网吧"];
}
- (IBAction)selectAll:(id)sender {
  NSArray *array = [_dataBaseManager selectAll];
    NSLog(@"%ld", array.count);
    NSLog(@"%@", array);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
